package com.test.p06prototype.example01;

public class Client04 {
    public static void main(String[] args) {
        testNew(10);
        testClone(10);
    }


    public static void  testNew(int size){

        long start = System.currentTimeMillis();
        for(int i =0 ;i<size; i++){
            LapTop t = new LapTop();
        }
        long end = System.currentTimeMillis();
        System.out.println("new cost "+(end-start));
    }

    public static void  testClone(int size){

        long start = System.currentTimeMillis();
        LapTop t = new LapTop();
        for(int i =0 ;i<size; i++){
            try {
                Object clone = t.clone();
            } catch (CloneNotSupportedException e) {
                e.printStackTrace();
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("clone cost "+(end-start));
    }
}

class LapTop implements Cloneable{

    public LapTop(){
        try{
            //模拟长的构造过程
            Thread.sleep(10);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}